package hy.day3_02;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/info/*")
public class Info extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        Object userFromSession = session.getAttribute("u");
        Object userFromReq = req.getAttribute("u");
        String msg = "session获取数据："+userFromSession+",req获取数据："+userFromReq;
        String ops = req.getRequestURI();
        if(ops.contains("dis")){
            System.out.println("转发请求，"+msg);
        }else {
            System.out.println("异步请求，"+msg);
        }
        resp.getWriter().println(userFromSession);
    }
}